<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/8
 * Time: 13:47
 */

namespace Fanpaiji\SuanFa;


use Fanpaiji\Tools;

class Base
{

    public function __construct(  )
    {

    }

    public function hanoi( int $n, $A, $B, $C)
    {
        if ( $n == 1 ) {
            printf( "Move sheet %d from %s to %s <br> \r\n", $n, $A, $C);
        } else {
            $this->hanoi( $n-1, $A, $C, $B );
            printf("Move sheet %d from %s to %s <br> \r\n", $n, $A, $C);
            $this->hanoi( $n-1, $B, $A, $C);
        }
    }


    public function long_combi(int $n, int $r){
//        echo $n .'---'.$r.'<br>';
        $p = 1;
        for( $i = 1; $i <= $r; $i++) {
            $p = $p * ($n - $i + 1) / $i;
        }
        return $p;
    }

    public function paint($Num = 12)
    {
        for ($n = 0; $n <= $Num; $n++) {
            for ($r = 0; $r <= $n; $r++) {
                /* 排版设定开始 */
                if ($r == 0) {
                    for ($i = 0; $i <= ($Num - $n); $i++) {
                        printf("%3s", '&nbsp' );
                    }
                } else {
                    printf("%3s",  '&nbsp' );
                }
//                $p = 1;
                printf("%3d", $this->long_combi($n, $r) );
//                printf("%d", $this->long_combi($n, $r) );
            } /* 排版设定结束 */
            printf("<br>");
        }

    }

}